package com.speedchina.common.rsa.resolver;

import com.speedchina.common.rsa.service.impl.RSARedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ：wangxiaodong
 * @description：TODO
 * @date ：2021/4/18 10:55
 */
@Slf4j
@Configuration
public class MethodArgumentResolver {
    @Autowired
    private RequestMappingHandlerAdapter adapter;
    @Autowired
    RSARedisService rsaRedisService;

    @PostConstruct
    public void injectSelfMethodArgumentResolver() {
        RequestBodyRSAArgumentResolver requestBodyRSAArgumentResolver = new RequestBodyRSAArgumentResolver();
        requestBodyRSAArgumentResolver.setRsaService(rsaRedisService);
        log.info("Init RequestBodyRSA Resolver");
        List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<HandlerMethodArgumentResolver>();
        argumentResolvers.add(requestBodyRSAArgumentResolver);
        argumentResolvers.addAll(adapter.getArgumentResolvers());
        adapter.setArgumentResolvers(argumentResolvers);
    }
}
